package mapper;


import org.apache.ibatis.annotations.*;
import pojo.Brand;

import java.util.List;

public interface BrandMapper {

     //查询所有品牌
    @Select("select * from t_brand")
    @ResultMap("brandResultMap")
    List<Brand> selectAll();
    //插入品牌的方法
    @ResultMap("brandResultMap")
    @Insert("insert into t_brand values(null,#{brandName},#{companyName},#{ordered},#{description},#{status})")
    void add(Brand brand);
    //单个查询
    @Select("select * from t_brand where id = #{id}")
    @ResultMap("brandResultMap")
    Brand selectById(int id);
    //修改品牌
    @ResultMap("brandResultMap")
    @Update("update t_brand set brand_name=#{brandName},company_name=#{companyName}," +
            "ordered=#{ordered},description=#{description},status=#{status}"+
            " where id=#{id}")
    void update(Brand brand);
    //删除品牌
    @ResultMap("brandResultMap")
    @Delete("delete from t_brand where id=#{id}")
    void deleteById(int id);

    //以下是分页查询
    //分页查询所有品牌
    @ResultMap("brandResultMap")
    @Select("select * from t_brand limit #{beginIndex},#{pageSize}")
    List<Brand> selectAllPage(@Param("beginIndex") int beginIndex,
                              @Param("pageSize") int pageSize);
    //查询品牌总数量
    @Select("SELECT count(1) FROM t_brand")
    int selectCount();
}
